﻿@using KRM.Core
@using KRM.Core.Library
@model KRM.Core.tblTicket
@{
    var disabled = "disabled";
}
<div class="tab-pane active" id="viewticket_@Model.TicketID">
    <div class="row-fluid">
        @*<form style="display: none" method="POST" id="frUploadfile_@Model.TicketID" enctype="multipart/form-data">
            <input type="file" name="FileUpload" style="float: right" id="inputUploadfile_@Model.TicketID" onchange="$('#frUploadfile_@Model.TicketID').submit()"/>
        </form>*@
        <form style="margin:0" id="frViewTicket_@Model.TicketID" method="POST">
            <div class="row-fluid">
                <div class="span4">
                    <input type="hidden" id="action_@Model.TicketID" name ="actionId" value="@Model.StatusID"/>
                    <input type="hidden" name="ticketId" value="@Model.TicketID"/>
                    <input type="hidden" id="hfaddtask_@Model.TicketID" value="false"/>
                    <input type="hidden" id="hfcommentOrSubmit_@Model.TicketID" value="" name="commentOrSubmit"/>
                    @Html.Partial("Partial/_MessageResult")
                    <div class="fieldset">
                        <div class="row-fluid">
                            <div class="span3">Assign To</div>
                            <div class="span9">
                                @if (ViewBag.Enable)
                                {
                                        
                                    @Html.DropDownList("AssignToUserId", null, new { @class = "input-block-level" })
                                }
                                else
                                {
                                    @Html.DropDownList("AssignToUserId", null, new { @class = "input-block-level", disabled })
                                    <input type="hidden" name="AssignToUserId" value="@(Model.AssignedToUserID ?? 0)"/>
                                }
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span3">Completed</div>
                            <div class="span5">
                                <div id="datetimepicker2_@Model.TicketID" class="input-append">
                                    <input data-format="MM/dd/yyyy" type="text" name="CompleteByDate" value="@((Model.DateCompleted ?? DateTime.Now).ToString("MM/dd/yyyy"))" required="required" style="width:61%;"/>
                                    <span class="add-on">
                                        <i data-date-icon="icon-calendar" class="icon-calendar"></i>
                                    </span>
                                </div>
                            </div>
                            <div class="span4">
                                <select name="CompleteByHrs" style="width: 52px; float: left; margin-left: -5px">
                                    @{var currentHrs = (Model.DateCompleted ?? DateTime.Now).Hour;}
                                    <option value="00">@currentHrs</option>
                                    <option value="18"@(currentHrs == 18 ? "selected='selected'" : "")>18</option>
                                    <option value="17"@(currentHrs == 17 ? "selected='selected'" : "")>17</option>
                                    <option value="16"@(currentHrs == 16 ? "selected='selected'" : "")>16</option>
                                    <option value="15"@(currentHrs == 15 ? "selected='selected'" : "")>15</option>
                                    <option value="14"@(currentHrs == 14 ? "selected='selected'" : "")>14</option>
                                    <option value="13"@(currentHrs == 13 ? "selected='selected'" : "")>13</option>
                                    <option value="12"@(currentHrs == 12 ? "selected='selected'" : "")>12</option>
                                    <option value="11"@(currentHrs == 11 ? "selected='selected'" : "")>11</option>
                                    <option value="10"@(currentHrs == 10 ? "selected='selected'" : "")>10</option>
                                    <option value="09"@(currentHrs == 9 ? "selected='selected'" : "")>9</option>
                                    <option value="08"@(currentHrs == 8 ? "selected='selected'" : "")>8</option>
                                </select>
                                <select name="CompleteByMins" style="width: 52px; float: left;">
                                    @{var currentMins = (Model.DateCompleted ?? DateTime.Now).Minute;}
                                    <option value="00"@(currentMins == 0 ? "selected='selected'" : "")>00</option>
                                    <option value="15"@(currentMins == 15 ? "selected='selected'" : "")>15</option>
                                    <option value="30"@(currentMins == 30 ? "selected='selected'" : "")>30</option>
                                    <option value="45"@(currentMins == 45 ? "selected='selected'" : "")>45</option>
                                </select>
                            </div>
                        </div>
                        @*<div class="row-fluid">
                            <div class="span3">Ccs</div>
                            <div class="span9 EmailCcTags">
                                <input type="text" name="EmailCc" id="EmailCc_@Model.TicketID" value="@Model.EmailCc">
                            </div>
                        </div>
                        <div class="row-fluid" style="margin-top: 10px">
                            <div class="span3">Bccs</div>
                            <div class="span9 EmailCcTags">
                                <input type="text" name="EmailBcc" id="EmailBcc_@Model.TicketID" value="@Model.EmailBcc">
                            </div>
                        </div>*@
                    </div>
                    @*<div class="fieldset">
                        <div class="row-fluid">
                            <div class="span3">Tag</div>
                            <div class="span9">
                                <div class="input-block-level" style="max-height: 75px; overflow: auto; margin-bottom: 10px; border: solid 1px rgb(204, 204, 204);">
                                    @foreach (tblTicketAllTag item in ViewBag.ListTags)
                                    {
                                        if (Model.TicketTags.Contains(c => c.TagID == item.TagID))
                                        {
                                        <div class="" style="margin-left: 10px;">
                                            <label class="checkbox">
                                                <input type="checkbox" name="Tags" checked="checked" value="@item.TagID"/>
                                                @item.Tag
                                            </label>
                                        </div>
                                        }
                                        else
                                        {
                                        <div class="" style="margin-left: 10px;">
                                            <label class="checkbox">
                                                <input type="checkbox" name="Tags" value="@item.TagID"/>
                                                @item.Tag
                                            </label>
                                        </div>
                                        }
                                    }
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span3">Description</div>
                            <div class="span9">
                                <textarea class="input-block-level" name="Description">@Model.Description</textarea>
                            </div>
                        </div>
                    </div>*@
                    <div class="fieldset ticket-left">
                        @Html.Partial("Partial/Ticket/_TicketRelations")
                    </div>
                    <div class="border-padding10">
                        @*<label style="display:inline-block"><input type="checkbox" class="cbcheck" value="True" id="SubmitAsAddTask_@Model.TicketID"/> Add task</label>*@
                        <button type="button" class="btn btn-success w90 bold" onclick="$('#hfaddtask_@Model.TicketID').val('true'); $('#frViewTicket_@Model.TicketID').submit();">Add Task</button>
                        <button type="button" class="btn btn-primary w90 bold" onclick="$('#hfcommentOrSubmit_@Model.TicketID').val('submit'); $('#frViewTicket_@Model.TicketID').submit();">Submit</button>
                        @if (Model.AssignedToUserID == 0 || Model.AssignedToUserID == null)
                        {
                            <button type="button" class="btn btn-default" onclick="RetreiveTicket(@Model.TicketID)">Retrieve!</button> 
                        }
                    </div>
                </div>
                <div class="span8" style="margin-left: 20px;">
                    <div class="fieldset" style="padding-left: 0px; padding-right: 0px;">
                        <div class="box-title" style="padding: 0px 0 7px 10px; border-bottom: 1px solid #ddd;">
                            @{
                                var statusClass = "";
                                switch (Model.StatusID)
                                {
                                    case (int)TicketStatus.New:
                                        statusClass = "label-warning";
                                        break;
                                    case (int)TicketStatus.Assigned:
                                        statusClass = "label-important";
                                        break;
                                    case (int)TicketStatus.Pending:
                                        statusClass = "label-info";
                                        break;
                                    case (int)TicketStatus.Solved:
                                        statusClass = "label-inverse";
                                        break;
                                    case (int)TicketStatus.Started:
                                        statusClass = "label-success";
                                        break;
                                    case (int)TicketStatus.Replied:
                                        statusClass = "label-blue";
                                        break;
                                    case (int)TicketStatus.Closed:
                                        statusClass = "";
                                        break;
                                }
                            }
                            <h5>
                                <i class="icon-envelope" style="color: #777"></i>
                                #@Model.TicketID @Model.Subject
                            </h5>
                            <div class="row-fluid">
                                <div class="span8">
                                    <span class="label @statusClass">@Model.Status.Status</span>
                                    @Model.DateAdded | @if (Model.OriginalEmail.SentByUser != null)
                                                       {<b>@Model.OriginalEmail.SentByUser.Username</b>@(" <" + Model.OriginalEmail.From + ">")}
                                                       else
                                                       {@Model.OriginalEmail.From}

                                </div>
                                <div class="span4">
                                    <a onclick="ViewTicketHistory(@Model.TicketID)" class="btn" style="float:right;padding-top: 3px;padding-bottom: 3px;padding-right: 5px;padding-left: 5px;margin-top: -3px;margin-right: 20px;">
                                        <i class="icon-time"></i>History
                                    </a>

                                    <a onclick="AddBlackList('@Model.OriginalEmail.From')" class="btn" style="float:right;padding-top: 3px;padding-bottom: 3px;padding-right: 5px;padding-left: 5px;margin-top: -3px;margin-right: 10px;">
                                        <i class="icon-book"></i>Add to blacklist
                                    </a>
                                </div>
                            </div>
                            <div class="TicketCommentDetail scrollable" data-visible="true">
                                <div class="box">
                                    <div class="box-content" style="padding: 20px 20px 0px 10px">
                                        <div class="row-fluid">
                                            <div class="span1">
                                                <img alt="" src="/Upload/Avatar/@(Users.Current(User.Identity.Name).Avatar ?? "avatar-default.jpg")" style="text-align: center; height: 40px; max-width: 40px; background-color: #ddd !important;">
                                            </div>
                                            <div class="span11">
                                                <input type="hidden" value="1" name="IsPublicReply" id="IsPublicReply_@Model.TicketID"/>
                                                <button type="button" class="btn btn-primary"id="btnSetPublicReply_@Model.TicketID" onclick="SetIsPublicReply(1,@Model.TicketID)">Public reply</button>
                                                <button type="button" class="btn" id="btnSetInternalNote_@Model.TicketID" onclick="SetIsPublicReply(0,@Model.TicketID)">Internal note</button>
                                                <span id="noteIsReply_@Model.TicketID" class="ticket-comment-time">| your comment is sent to the ticket requester</span>
                                                <button type="button" class="btn btn-primary pull-right" onclick="ShowQuickReply(@Model.TicketID, '@Model.OriginalEmail.From')">Quick reply</button>
                                                <textarea class="input-block-level" rows="3" id="NewComment_@Model.TicketID" name="NewComment"></textarea>
                                                <input type="text" name="EmailCc" id="EmailCc_@Model.TicketID" value="@Model.EmailCc" class="input-block-level" placeholder="Cc" style="display: none">
                                                <input type="text" name="EmailBcc" id="EmailBcc_@Model.TicketID" value="@Model.EmailBcc" class="input-block-level" placeholder="Bcc" style="display: none">
                                                <div class="row-fluid">
                                                    <div class="span2">
                                                        <a href="javascript:;" onclick="$('#EmailCc_@Model.TicketID').toggle('fast');">Cc</a>
                                                        <a href="javascript:;" onclick="$('#EmailBcc_@Model.TicketID').toggle('fast');">Bcc</a>
                                                    </div>
                                                    <div class="span5">
                                                    </div>
                                                    <div class="span5 text-right">
                                                        <a href="javascript:;" onclick="$('#UploadAttachment_@Model.TicketID').modal('show')" style="margin-right: 10px">Add Attachments</a>
                                                        @*<div id="">Upload</div>*@

                                                        @*<a onclick="$('#inputUploadfile_@Model.TicketID').click()" style="cursor: pointer; margin-right:10px"></a>*@
                                                        <input type="button" value="Comment" onclick="commentnotsubmitticket(@Model.TicketID)"/>
                                                    </div>
                                                </div>
                                                <ul id="LstAttachment_@Model.TicketID">
                                                </ul>
                                                <div id="UploadAttachment_@Model.TicketID" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                                        <h4>Upload file attachments</h4>
                                                    </div>
                                                    <div class="modal-body" style="min-height: 200px">
                                                        <a href="javascript:;" id="mulitplefileuploader_@Model.TicketID" style="margin-right: 10px">Select files</a>
                                                        <div id="status_@Model.TicketID"></div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button class="btn btn-primary w100" data-dismiss="modal" aria-hidden="true">Done</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="box">
                                    <div class="box-title" style="padding: 0px 0 7px 10px;">
                                        <a class="btn btn-mini" style="padding: 2px 10px; border-radius: 2px;" onclick="refreshcomment($(this),@Model.TicketID)">
                                            <i class="icon-refresh"></i>
                                        </a>
                                        All comments
                                    </div>
                                    <div class="box-content" style="padding: 20px 20px 20px 10px">

                                        <div id="commentticket_@(Model.TicketID)">
                                            @Html.Partial("Partial/Ticket/_TicketComments")
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row-fluid" style="padding-top: 15px; border-top: 1px solid #ddd;">
                                <div class="span5">
                                </div>
                                <div class="span7 text-right">
                                    @if (Model.StatusID == 6)
                                    {
                                        <button type="button" class="btn btn-danger w90 bold" onclick="$('#action_@Model.TicketID').val(2); $('#frViewTicket_@Model.TicketID').submit();">Open</button>
                                    }
                                    else
                                    {
                                        <button type="button" class="btn btn-success w90 bold" onclick="$('#action_@Model.TicketID').val(6); $('#frViewTicket_@Model.TicketID').submit();">Start</button>
                                    }
                                    <button type="button" class="btn btn-info w90 bold" onclick="$('#action_@Model.TicketID').val(3); $('#frViewTicket_@Model.TicketID').submit();">Pending</button>
                                    <button type="button" class="btn btn-inverse w90 bold" onclick="$('#action_@Model.TicketID').val(4); $('#frViewTicket_@Model.TicketID').submit();">Solved</button>
                                    <button type="button" class="btn w90 bold" style="background: #999; color: white; margin:0 20px 0 0" onclick="$('#action_@Model.TicketID').val(5); $('#frViewTicket_@Model.TicketID').submit();">Close</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
